set.seed(123)
data <- data.frame(
Order_Date = seq(as.Date("2023-01-01"), as.Date("2023-12-31"), by="day"),
Category = sample(c("Furniture", "Office Supplies", "Technology"), 365, replace=TRUE),
Sales = runif(365, 100, 1000),
Profit = runif(365, -50, 200),
Region = sample(c("East", "West", "Central", "South"), 365, replace=TRUE),
Discount = runif(365, 0, 0.3)
)
monthly_sales <- data %>%
mutate(Month = floor_date(Order_Date, "month")) %>%
group_by(Month) %>%
summarise(Total_Sales = sum(Sales))
ggplot(monthly_sales, aes(x=Month, y=Total_Sales)) +
geom_line(color="#2c3e50", size=1) +
geom_point(color="#e74c3c", size=2) +
labs(title = "Monthly Sales Trend (2023)",
subtitle = "Total sales growth over the year",
x="Month", y="Total Sales ($)") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
plot.subtitle = element_text(hjust = 0.5, size = 12),
plot.margin = margin(t = 50)
)
Figure 1: This chart shows the monthly sales trend for 2023.
cat_profit <- data %>%
group_by(Category) %>%
summarise(Total_Profit = sum(Profit))
ggplot(cat_profit, aes(x=Category, y=Total_Profit, fill= Category)) +
geom_bar(stat = "identity") +
scale_fill_brewer(palette="Set2") +
labs(title="Total Profit by Category",
x="Product Category", y="Profit ($)") +
theme_classic() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
plot.subtitle = element_text(hjust = 0.5, size = 12),
plot.margin = margin(t = 50)
)
Figure 1: This chart shows the monthly sales trend for 2023.
ship_data <- data %>%
count(Category)
ggplot(ship_data, aes(x=Category, y=n, fill=Category)) +
geom_col() +
labs(title="Preferred Categories (Order Count)",
x="Category", y="Number of Orders") +
theme_light() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
plot.subtitle = element_text(hjust = 0.5, size = 12),
plot.margin = margin(t = 50)
)
Figure 1: This chart shows the monthly sales trend for 2023.
p <- ggplot(data, aes(x=Discount, y=Profit, color=Category)) +
geom_point(alpha=0.6) +
geom_smooth(method="lm", color="black") +
labs(title="Relationship between Discount and Profit",
x="Discount (0 - 0.3)", y="Profit / Loss ($)") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold"),
plot.subtitle = element_text(hjust = 0.5)
)
ggplotly(p) %>%
layout(
margin = list(t = 100),
legend = list(
orientation = "v",
xanchor = "left",
yanchor = "middle",
x = 1.1,
y = 0.5,
bgcolor = "#F8F9F9",
bordercolor = "#D5DBDB",
borderwidth = 1,
title = list(text = "<b> Category </b>")
)
) %>%
htmltools::div(align = "center")
regional_sales <- data %>%
group_by(Region) %>%
summarise(Total_Sales = sum(Sales))
ggplot(regional_sales, aes(x=reorder(Region, -Total_Sales), y=Total_Sales, fill=Region)) +
geom_bar(stat="identity") +
labs(title="Total Sales by Region",
x="Region", y="Total Sales ($)") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
plot.subtitle = element_text(hjust = 0.5, size = 12),
plot.margin = margin(t = 50)
)
Figure 1: This chart shows the monthly sales trend for 2023.
Based on the comprehensive analysis of the Superstore Sales data, several key insights have been identified that can guide future business strategies: